/**
 * 
 */
package entities;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 * @author dga
 *
 */
@Entity()
@NamedQueries({
	@NamedQuery(name = "Client.findAll", query = "Select c From Client c"),
	@NamedQuery(name = "Client.findLikeOnLogin", query = "Select c From Client c where c.login like :like")
})
public class Client extends Persistent {
	private String login;
	private String password;
	private String nom;
	private String prenom;
	private String adresse;
	private String email;
	private String telephone;
	private int role;
	@Lob
	private byte[] photo;
	
	private List<Order> commandes = new ArrayList<Order>();

	public boolean equals(Object other){
		if(other != null && other instanceof Client)
			return getLogin().equals(((Client)other).getLogin());
		return false;
	}
	public int hashCode(){
		return getLogin().hashCode();
	}


	@Column(nullable = false, unique=true)
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	@OneToMany(mappedBy="client",cascade ={CascadeType.PERSIST, CascadeType.REMOVE})
	public List<Order> getCommandes() {
		return commandes;
	}
	public void setCommandes(List<Order> commandes) {
		this.commandes = commandes;
	}
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getPrenom() {
		return prenom;
	}
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
	public String getAdresse() {
		return adresse;
	}
	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	public int getRole() {
		return role;
	}
	public void setRole(int role) {
		this.role = role;
	}
	public byte[] getPhoto() {
		return photo;
	}
	public void setPhoto(byte[] photo) {
		this.photo = photo;
	}


}
